package com.crm.system.controller.customerManager;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.common.util.CommonUtils;
import com.crm.model.entity.cluePoolManager.ClueVisitRecord;
import com.crm.model.entity.common.Dictionary;
import com.crm.model.entity.contactManager.Contact;
import com.crm.model.entity.contractManager.CustomerContract;
import com.crm.model.entity.customerManager.*;
import com.crm.model.entity.finishOrderProduct.FinishOrderProduct;
import com.crm.model.entity.orderManager.CustomerProductOrder;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.qo.customerManager.AnalyseCustomerQO;
import com.crm.model.qo.customerManager.CustomerAddQO;
import com.crm.model.qo.customerManager.CustomerQO;
import com.crm.model.qo.customerManager.MoveCustomerQO;
import com.crm.model.vo.cluePoolManager.ClueFollowVO;
import com.crm.model.vo.customerManager.*;
import com.crm.model.vo.opportunityManager.OpportunityCustomerVO;
import com.crm.system.service.contactManager.ContactService;
import com.crm.system.service.customerManager.CustomerContactPersonService;
import com.crm.system.service.customerManager.CustomerExchangeService;
import com.crm.system.service.customerManager.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ Author ：pym
 * @ Date   ：2021/1/18 15:53
 */
@RestController
@RequestMapping("/exchange")
@Slf4j
public class CustomerExchangeController {

    @Autowired
    CustomerExchangeService customerExchangeService;

    /**
     * 客户详情-兑换列表
     * @param request
     * @param pageIndex 页码
     * @param pageSize 条数
     * @param sortName 分组名称
     * @param sortOrder 分组方式
     * @param customerId 客户id
     * @return
     */
    @PostMapping("/exchangeList")
    public DataResponse exchangeList(HttpServletRequest request,
                                         @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                         @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                         @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                         @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                         @RequestParam(value="customerId",required = false) String customerId//排序规则(asc/desc)
    ){
        try{
            DhPageInfo<Exchange> list = customerExchangeService.exchangeList(pageIndex,pageSize,sortName,sortOrder,customerId);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("exchange exchangeList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 客户详情-兑换明细
     * @param exchangeId 兑换id
     * @return
     */
    @RequestMapping("/exchangeDetail")
    public DataResponse exchangeDetail(@RequestParam(value = "exchangeId") String exchangeId) {
        Map<String,Object> map = customerExchangeService.exchangeDetail(exchangeId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),map);
    }
}
